<template>
    <div>
      <m-head title="旅游英语"></m-head>
      <div class="top">
        <img :src="info.cover" alt="">
        <div class="info">
          <h3>{{info.name}}</h3>
          <p class="author">作者：<span>{{info.auther}}</span></p>
          <p class="price">价格：<span>{{info.price/100}}</span></p>
        </div>
      </div>
      <div class="list">
        <div class="title">
          <h3>图书介绍</h3>
        </div>
        <div class="intro">
          <p>{{info.introduction}}</p>
        </div>
      </div>
      <div class="fix">
        <button @click="$router.push({path:'/order',query:{'id':info.id,'type':2}})">立即购买</button>
      </div>
    </div>
</template>

<script>
import MHead from './MHeader'
import * as info from '../api/info'
import * as order from '../api/order'
import wxConfig from '../api/wx'
export default {
  name: 'book-detail',
  data: function () {
    return {
      id: 0,
      img: '../../static/images/book.jpg',
      name: '旅游英语',
      price: '15.00',
      author: '张雪峰',
      intro: '旅游英语课程包含了21课内容，通过学习，你能掌握自我介绍，数字应用、订酒店、确认时间、日期、的日常英语沟通，以及开口说话必会的工具箱，除此之外，你还能学会与人交往互动的沟通表达，比如： 邀约朋友、表达意见和情绪、人打车，三餐问候等等。这些旅游交流的场景句，全部配有对应的视屏和英频，每一个场景的真实演绎的，因此，这样学习不仅会提高你的记忆效率3倍以上，同时，在学习的过程中，你会持续保持学习英语的兴趣和愉悦感。 通过此课程的学习，你能掌握1000多英语实用高频词，100多高频短句，50多组英语发音，你能迅速从英语零基础过渡到独立进行旅游沟通交流，帮助您在旅程中畅通无阻。环球的梦想早已不再遥远。',
      info: { }
    }
  },
  components: {
    'm-head': MHead
  },
  mounted(){
    this.id = this.$route.query.id
    this.getBook(this.id)
    wxConfig.wxRegister(this.wxRegister())
  },
  methods:{
    wxRegister () {
      this.wxShareTimeline()
      this.wxShareAppMessage()
    },
    wxShareTimeline () {
      let that = this
      // 微信自定义分享到朋友圈
      let option = {
        title: that.info.name, // 分享标题, 请自行替换
        link: window.location.href.split('#')[0], // 分享链接，根据自身项目决定是否需要split
        imgUrl: that.info.cover, // 分享图标, 请自行替换，需要绝对路径
        success: () => {
          alert('分享成功')
        },
        error: () => {
          alert('已取消分享')
        }
      }
      // 将配置注入通用方法
      wxConfig.ShareTimeline(option)
    },
    wxShareAppMessage () {
      let that = this
      // 微信自定义分享给朋友
      let option = {
        title: that.info.name, // 分享标题, 请自行替换
        link: window.location.href.split('#')[0], // 分享链接，根据自身项目决定是否需要split
        imgUrl: that.info.cover, // 分享图标, 请自行替换，需要绝对路径
        desc: that.info.introduction, // 分享描述, 请自行替换
        success: () => {
          alert('分享成功')
        },
        error: () => {
          alert('已取消分享')
        }
      }
      // 将配置注入通用方法
      wxConfig.ShareAppMessage(option)
    },
    getBook(id){
      info.getBook(id).then(res=>{
        this.info = res.data
      })
    },
    order () {
      order.orders(this.id, 2).then(res => {
        order.sign(res.data.id).then(res => {
          const data = res.data
          wxConfig.wxPay(data)
          // this.onBridgeReady(param)
        })
      })
    }
  }
}
</script>

<style scoped>
.top{
  display: flex;
  align-items: flex-start;
  padding: .4rem .3rem;
  border-bottom: .2rem solid #f1f1f1;
}
.top img{
  width: 2.8rem;
  margin-right: .3rem;
}
.info{
  display: flex;
  justify-content: space-between;
  flex-direction: column;
}
.info h3{
  font-size: .44rem;
  width: 100%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  color: #000;
  margin-bottom: 2px;
}
.info .price{
  color: #ed702d;
  font-size: .38rem;
  margin-bottom: .16rem;
}
.info .author{
  margin-bottom: .3rem;
  font-size: .38rem;
  color: #888;
}
.title{
  height: 1rem;
  line-height: 1rem;
  border-bottom: 1px solid #eee;
  padding: 0 .3rem;
}
.title h3{
  position: relative;
  padding-left: .3rem;
  font-size: .4rem;
  color: #333;
}
.title h3:before{
  content: '';
  position: absolute;
  top: 25%;
  left: 0;
  height: 50%;
  border-left: 4px solid #ed702d;
}
.intro{
  line-height: .6rem;
  font-size: .36rem;
  padding: .3rem;
  color: #555;
}
.fix{
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 1.2rem;
  line-height: 1.2rem;
}
.fix button{
  background: #0959c8;
  display: block;
  width: 100%;
  border: none;
  height: 1.2rem;
  line-height: 1.2;
  text-align: center;
  color: #fff;
  font-size: .48rem;
  letter-spacing: 2px;
}
</style>
